//
//  VisitorView.swift
//  SwiftWB
//
//  Created by 钟清 on 17/3/25.
//  Copyright © 2017年 Zhong Qing. All rights reserved.
//

import UIKit

//protocol VisitorViewDelegate : NSObjectProtocol {
//    func visitorViewDidClickLoginButton(visitor : VisitorView)
//    func visitorViewDidClickRegisterButton(visitor : VisitorView)
//}
class VisitorView: UIView {
    
    @IBOutlet weak var rotationView: UIImageView!
    @IBOutlet weak var imageView: UIImageView!
    @IBOutlet weak var registerButton: UIButton!
    @IBOutlet weak var loginButton: UIButton!
    @IBOutlet weak var textLabel: UILabel!
    
    // weak var delegate : VisitorViewDelegate?

    // MARK: - 外部控制方法
    /// 快速创建方法
    class func visitorView() -> VisitorView {
        return NSBundle.mainBundle().loadNibNamed("VisitorView", owner: nil, options: nil).first as! VisitorView
    }
    
    /// 设置访客视图上的数据
    func setUpVisitorInfo(imageName : String?, text : String) {
        textLabel.text = text
        guard let name = imageName else { // 没有设置图标，即首页
            // 首页转盘动画
            startAnimation()
            return
        }
        /// 非首页
        rotationView.hidden = true
        imageView.image = UIImage(named: name)
        
        }
    // MARK: - 内部控制方法
    /// 转盘动画
    func startAnimation() {
        let anim = CABasicAnimation(keyPath: "transform.rotation")
        anim.toValue = 2 * M_PI
        anim.duration = 6
        anim.repeatCount = MAXFLOAT
        anim.removedOnCompletion = false
        rotationView.layer.addAnimation(anim, forKey: nil)
        
    }
    
    // MARK: - 按钮点击
//    @IBAction func registerButtonClick(sender: AnyObject) {
//        delegate?.visitorViewDidClickRegisterButton(self)
//    }
//    @IBAction func loginButtonClick(sender: AnyObject) {
//        delegate?.visitorViewDidClickLoginButton(self)
//    }

}
